package cn.doitedu.rule.engine.utils;

import cn.doitedu.rule.engine.beans.EventBean;
import cn.doitedu.rule.engine.beans.EventParam;

import java.util.Set;

public class EventParamComparator {


    /**
     * 比较规则条件中的事件条件和实时事件是否匹配
     * @param param1
     * @param target
     * @return
     */
    public static boolean compare(EventParam param1,EventParam target){

        if(param1.getEventId().equals(target.getEventId())){

            Set<String> keys = param1.getEventProperties().keySet();
            for (String key : keys) {
                String targetValue = target.getEventProperties().get(key);
                if(!param1.getEventProperties().get(key).equals(targetValue)) return false;
            }
            return true;
        }


        return false;
    };

    public static boolean compare(EventParam param1, EventBean target){

        if(param1.getEventId().equals(target.getEventId())){

            Set<String> keys = param1.getEventProperties().keySet();
            for (String key : keys) {
                String targetValue = target.getProperties().get(key);
                if(!param1.getEventProperties().get(key).equals(targetValue)) return false;
            }
            return true;
        }

        return false;
    };



}
